//
//  AddAddressView.m
//  HAODE
//
//  Created by panquanReabam.com on 16/5/6.
//  Copyright © 2016年 reabam.com. All rights reserved.
//

#import "AddAddressView.h"
#import "UIAlertView+show.h"
@interface AddAddressView()<UITextFieldDelegate,UIGestureRecognizerDelegate>

@property (nonatomic,weak) id delegate;

@end
@implementation AddAddressView

{
NSString*isDefault;
 BOOL saveAccount;

}

@synthesize mDelegate;
#pragma mark LifeCycle
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initUI];
    }
    return self;
}
#pragma mark InitUI
- (void)initUI
{
    self .backgroundColor = [UIColor whiteColor];
    UILabel *line1 = [[UILabel alloc]initWithFrame:CGRectMake(20,170*ScreenHeight/1334+64, ScreenWidth-40, 0.40)];
    line1.backgroundColor = qianhuiColor;
    [self addSubview:line1];
    UILabel *line2 = [[UILabel alloc]initWithFrame:CGRectMake(20,255*ScreenHeight/1334+64, ScreenWidth-40, 0.40)];
    line2.backgroundColor = qianhuiColor;
    [self addSubview:line2];
    UILabel *line3 = [[UILabel alloc]initWithFrame:CGRectMake(20,345*ScreenHeight/1334+64, ScreenWidth-40, 0.40)];
    line3.backgroundColor = qianhuiColor;
    [self addSubview:line3];
    UILabel *line4 = [[UILabel alloc]initWithFrame:CGRectMake(20,435*ScreenHeight/1334+64, ScreenWidth-40, 0.40)];
    line4.backgroundColor = qianhuiColor;
    [self addSubview:line4];
    
    UILabel* TheConsigneeLabel=[[UILabel alloc]initWithFrame:CGRectMake(20.0f,90*ScreenHeight/1334+64, 80.0f,80*ScreenHeight/1334)];
    TheConsigneeLabel.text=@"收货人";
    [TheConsigneeLabel setTextColor:[UIColor colorWithRed:153.00/255.00 green:153/255.00 blue:153/255.00 alpha:1.0]];
    TheConsigneeLabel.font = [UIFont systemFontOfSize:contenfot];
    [self addSubview:TheConsigneeLabel];
    
    _userNameTextField = [[UITextField alloc] initWithFrame:CGRectMake(TheConsigneeLabel.right+3,90*ScreenHeight/1334+64, 180.0f,80*ScreenHeight/1334)];
    [_userNameTextField setBorderStyle:UITextBorderStyleNone]; //外框类型
    _userNameTextField.keyboardType = UIKeyboardTypeDefault;
    _userNameTextField.placeholder = @"请输入收货人姓名"; //默认显示的字
    _userNameTextField.font=[UIFont systemFontOfSize:contenfot];
    _userNameTextField.returnKeyType = UIReturnKeyDone;
    _userNameTextField.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
    _userNameTextField.delegate = self;
    _userNameTextField.tag=22;
    [self addSubview:_userNameTextField];
    
    
    UIView*myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
    myToolBar.backgroundColor=jianpancolor;
    UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
    [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [tubtnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:tubtnDone];
    UIButton*btnDone=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
    [btnDone setTitle:@"确定" forState:UIControlStateNormal];
    [btnDone setTitleColor:jianpancolor1 forState:UIControlStateNormal];
    btnDone .titleLabel .font=[UIFont systemFontOfSize:keyboardFot];
    [btnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:btnDone];
    myToolBar.alpha=alp;
    UIButton* bigBtnDone=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
    [bigBtnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:bigBtnDone];
    _userNameTextField.inputAccessoryView = myToolBar;
    
    
    UILabel* telLabel=[[UILabel alloc]initWithFrame:CGRectMake(20.0f,170*ScreenHeight/1334+64, 80.0f,80*ScreenHeight/1334)];
    telLabel.text=@"手机号";
    [telLabel setTextColor:[UIColor colorWithRed:153.00/255.00 green:153/255.00 blue:153/255.00 alpha:1.0]];
    telLabel.font = [UIFont systemFontOfSize:contenfot];
    [self addSubview:telLabel];
    _telTextField = [[UITextField alloc] initWithFrame:CGRectMake(telLabel.right+3,170*ScreenHeight/1334+64, 180.0f,80*ScreenHeight/1334)];
    [_telTextField setBorderStyle:UITextBorderStyleNone]; //外框类型
    _telTextField.placeholder = @"请输入会员的手机号码"; //默认显示的字
    _telTextField.keyboardType = UIKeyboardTypeDecimalPad;
    _telTextField.autocorrectionType = UITextAutocorrectionTypeNo;
    _telTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
    _telTextField.returnKeyType = UIReturnKeyDone;
    _telTextField.font=[UIFont systemFontOfSize:contenfot];
    _telTextField.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
    _telTextField.delegate = self;
    [_telTextField addTarget:self action:@selector(userNumberLimitTextLength:) forControlEvents:UIControlEventEditingChanged];
    [self addSubview:_telTextField];
    _telTextField.inputAccessoryView = myToolBar;
    
    
    
    UILabel* region=[[UILabel alloc]initWithFrame:CGRectMake(20.0f,260*ScreenHeight/1334+64, 80.0f,80*ScreenHeight/1334)];
    region.text=@"地区";
    [region setTextColor:[UIColor colorWithRed:153.00/255.00 green:153/255.00 blue:153/255.00 alpha:1.0]];
    region.font = [UIFont systemFontOfSize:contenfot];
    [self addSubview:region];

    
    _regionTextField = [[UITextField alloc] initWithFrame:CGRectMake(region.right+3,260*ScreenHeight/1334+64, 180.0f,80*ScreenHeight/1334)];
    [_regionTextField setBorderStyle:UITextBorderStyleNone]; //外框类型
    _regionTextField.placeholder = @"请选择现在所在地区"; //默认显示的字
    _regionTextField.autocorrectionType = UITextAutocorrectionTypeNo;
    _regionTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
    _regionTextField.returnKeyType = UIReturnKeyDone;
    _regionTextField.font=[UIFont systemFontOfSize:contenfot];
    _regionTextField.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
    _regionTextField.delegate = self;
    [_regionTextField setUserInteractionEnabled:NO];
    [self addSubview:_regionTextField];
    
    
    UILabel* addressLabel=[[UILabel alloc]initWithFrame:CGRectMake(20.0f,350*ScreenHeight/1334+64, 80.0f,80*ScreenHeight/1334)];
    addressLabel.text=@"详细地址";
    [addressLabel setTextColor:[UIColor colorWithRed:153.00/255.00 green:153/255.00 blue:153/255.00 alpha:1.0]];
    addressLabel.font = [UIFont systemFontOfSize:contenfot];
    [self addSubview:addressLabel];
    _addressTextField = [[UITextField alloc] initWithFrame:CGRectMake(telLabel.right+3,350*ScreenHeight/1334+64,500*ScreenWidth/750,80*ScreenHeight/1334)];
    [_addressTextField setBorderStyle:UITextBorderStyleNone]; //外框类型
    _addressTextField.placeholder = @"请输入详细地址"; //默认显示的字
    _addressTextField.keyboardType = UIKeyboardTypeDefault;
    _addressTextField.autocorrectionType = UITextAutocorrectionTypeNo;
    _addressTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
    _addressTextField.returnKeyType = UIReturnKeyDone;
    _addressTextField.font=[UIFont systemFontOfSize:contenfot];
    _addressTextField.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
    _addressTextField.delegate = self;
    [self addSubview:_addressTextField];
    
    
    _addressTextField.inputAccessoryView = myToolBar;
    
    
    UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
    singleFingerOne.numberOfTouchesRequired = 1; //手指数
    singleFingerOne.numberOfTapsRequired = 1; //tap次数
    singleFingerOne.delegate = self;
    [self addGestureRecognizer:singleFingerOne];

    UIButton*area=[[UIButton alloc]initWithFrame:CGRectMake(100, 260*ScreenHeight/1334+64, ScreenWidth, 88/2)];
    [area addTarget:self action:@selector(area) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:area];
    
    _chooseBtn = [[UIButton alloc] initWithFrame:CGRectMake(20, _addressTextField.bottom+20, 30, 30)];
    
    
    [_chooseBtn setImage:[UIImage imageNamed:@"jizhumima_normal"] forState:UIControlStateNormal];
    [_chooseBtn addTarget:self action:@selector(chooseBtn1:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_chooseBtn];
    
    UIButton*agreementBtn = [[UIButton alloc] initWithFrame:CGRectMake(10,_addressTextField.bottom+20, 44, 44)];
    [agreementBtn addTarget:self action:@selector(chooseBtn1:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:agreementBtn];
    
    
    UILabel* Rememberthepassword=[[UILabel alloc]initWithFrame:CGRectMake(_chooseBtn.right+2, _addressTextField.bottom+27, 120.0f, 16.0)];
    Rememberthepassword.text=@"  设置默认";
    Rememberthepassword.font = [UIFont systemFontOfSize: 15];
    [Rememberthepassword setTextColor:[UIColor grayColor]];
    [self addSubview:Rememberthepassword];
    
    
   
    UIButton* login = [[UIButton alloc] initWithFrame:CGRectMake(0, ScreenHeight-45, ScreenWidth, 45)];
    [login setTitle:@"确认" forState:UIControlStateNormal];
    [login setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    login.backgroundColor=luseColor;
    CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
    CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){204.0/255.0,153.0/255.0, 51.0/255.0, 1.0});
    [login.layer setBorderColor:tureBTncolorref];//边框颜色
    [login addTarget:self action:@selector(ture) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:login];
   
    
}




- (void)textFieldDidBeginEditing:(UITextField *)textField{
  [mDelegate cancelLocatePicker:@""];
    
}
- (void)area{

    [mDelegate area:@""];


}
//号码限制
- (void)userNumberLimitTextLength:(UITextField*)textField
{
    
    if ([textField.text length] >= 11)
    {
        textField.text = [textField.text substringToIndex:11];
        
        
        
        
    }
}
//回收键盘
-(void)closeKeyBoad
{
    [_addressTextField resignFirstResponder];
    [_regionTextField resignFirstResponder];
    [_telTextField resignFirstResponder];
    [_userNameTextField resignFirstResponder];
}
-(void)OnTapDone{
    [_addressTextField resignFirstResponder];
    [_regionTextField resignFirstResponder];
    [_telTextField resignFirstResponder];
    [_userNameTextField resignFirstResponder];
    
}
#pragma mark Event Handle

-(void)chooseBtn1:(id)sender
{
    saveAccount=!saveAccount;
    if (saveAccount) {
        isDefault=@"Y";
        
        [_chooseBtn setImage:[UIImage imageNamed:@"jizhumima_hight"] forState:UIControlStateNormal];
        [mDelegate isDefaultStr:isDefault];
    }
    else
    {   isDefault=@"N";
        [_chooseBtn setImage:[UIImage imageNamed:@"sheweimoren_normal"] forState:UIControlStateNormal];
        [mDelegate isDefaultStr:isDefault];
    }
    
}

- (void)ture
{
    
    [mDelegate ture:@""];
    
}

@end
